package com.cn.sl.server.api.system.menu.model.dto

import com.cn.sl.server.api.system.menu.model.entity.MenuEntity
import com.cn.sl.server.api.system.menu.model.enumerate.MenuType
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.NotEmpty

@Schema(description = "新增菜单")
data class AddButtonParam(
    /**
     * 父级id
     */
    @field:Schema(description = "父级id")
    val parentId: Long?,
    /**
     * 扩展属性
     */
    @NotEmpty(message = "扩展属性不能为空")
    @field:Schema(description = "扩展属性")
    val meta: Map<String, Any>?,
) {
    fun toDto(): AddButtonDto {
        return AddButtonDto(
            parentId = parentId,
            type = MenuType.BUTTON,
            meta = meta!!
        )
    }
}

data class AddButtonDto(
    /**
     * 父级id
     */
    val parentId: Long?,
    /**
     * 菜单类型
     */
    val type: MenuType,
    /**
     * 扩展属性
     */
    val meta: Map<String, Any>,
) {
    fun toEntity(): MenuEntity {
        val dto = this
        return MenuEntity().apply {
            this.parentId = dto.parentId
            this.type = dto.type
            this.meta = dto.meta
        }
    }
}